﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Main.master" AutoEventWireup="true" CodeBehind="MaterialLoan.aspx.cs" Inherits="UdrinkWater_Project.Officer.MaterialLoan" %>
<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">
 <script type="text/javascript">
    // <![CDATA[
     function ShowSertEmpWindow() {
         pcDataEmp.Show();
     }
     function ShowSertCusWindow() {
         pcCusData.Show();
     }
     function ShowSertProWindow() {
         pcMaterial.Show();
     }
    // ]]> 
    </script>
    <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
    <dx:ASPxPopupControl ID="pcMaterial" runat="server" HeaderText="ค้นหาวัตถุดิบ" 
        ClientInstanceName="pcMaterial" EnableViewState="False" 
        PopupHorizontalAlign="WindowCenter" PopupVerticalAlign="TopSides" 
        Width="900px">
        <ContentCollection>
<dx:PopupControlContentControl runat="server" SupportsDisabledAttribute="True">
    <dx:ASPxGridView ID="ASPxGridView3" runat="server" AutoGenerateColumns="False" 
        DataSourceID="SqlDataItem" KeyFieldName="Product_ID" 
        OnRowCommand="ASPxGridView4_RowCommand" Width="100%">
        <Columns>
            <dx:GridViewDataTextColumn Caption="รหัสสินค้า" FieldName="Product_ID" 
                ShowInCustomizationForm="True" VisibleIndex="1">
            </dx:GridViewDataTextColumn>
            <dx:GridViewDataTextColumn Caption="ชื่อสินค้า" FieldName="Product_name" 
                ShowInCustomizationForm="True" VisibleIndex="2">
            </dx:GridViewDataTextColumn>
            <dx:GridViewDataTextColumn Caption="ราคาต่อหน่วย" FieldName="Price" 
                ReadOnly="True" ShowInCustomizationForm="True" VisibleIndex="3">
            </dx:GridViewDataTextColumn>
            <dx:GridViewDataTextColumn Caption="หน่วยนับ" FieldName="Unit_Name" 
                ShowInCustomizationForm="True" VisibleIndex="4">
            </dx:GridViewDataTextColumn>
            <dx:GridViewDataTextColumn Caption="เลือก" ShowInCustomizationForm="True" 
                VisibleIndex="5">
                <DataItemTemplate>
                    <dx:ASPxButton ID="btSertProd" runat="server" 
                        CommandArgument='<%# Eval("Product_ID") %>' CommandName="Cmd_Select" 
                        Text="เลือก">
                        <ClientSideEvents Click="function(s, e) {
	pcMaterial.Hide();
}" />
                    </dx:ASPxButton>
                </DataItemTemplate>
            </dx:GridViewDataTextColumn>
        </Columns>
        <Settings ShowFilterRow="True" />
    </dx:ASPxGridView>
    <asp:SqlDataSource ID="SqlDataItem" runat="server" 
        ConnectionString="<%$ ConnectionStrings:DB_Udrink %>" 
        
        
        SelectCommand="SELECT TB_Product.Product_ID, TB_Product.Product_name, TB_Product.Unit, TB_Unit_Category.Unit_Name, TB_Product.Price FROM TB_Product INNER JOIN TB_Unit_Category ON TB_Product.Unit = TB_Unit_Category.Unit_ID"></asp:SqlDataSource>

            </dx:PopupControlContentControl>
</ContentCollection>
    </dx:ASPxPopupControl>
    <dx:ASPxRoundPanel ID="ASPxRoundPanel1" runat="server" 
        HeaderText="ยืม - คืน ของลูกค้า" Width="100%">
        <PanelCollection>
            <dx:PanelContent runat="server" SupportsDisabledAttribute="True">
                <table style="width:100%;">
                    <tr>
                        <td style="height: 18px; width: 475px">
                            <asp:Panel ID="Panel2" runat="server">
                                <table style="width:100%;">
                                    <tr>
                                        <td style="width: 105px">
                                            <dx:ASPxLabel ID="ASPxLabel3" runat="server" Text="วันที่และเวลา :">
                                            </dx:ASPxLabel>
                                        </td>
                                        <td style="width: 370px">
                                            <dx:ASPxTextBox ID="txtOrderDate" runat="server" BackColor="#D3E4A6" 
                                                ReadOnly="True" Width="225px">
                                            </dx:ASPxTextBox>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td style="width: 105px">
                                            <dx:ASPxLabel ID="ASPxLabel4" runat="server" Text="ชื่อ : ">
                                            </dx:ASPxLabel>
                                        </td>
                                        <td style="width: 370px">
                                            <dx:ASPxTextBox ID="txtFrist" runat="server" Width="225px">
                                            </dx:ASPxTextBox>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td style="width: 105px">
                                            <dx:ASPxLabel ID="ASPxLabel5" runat="server" Text="นามสกุล : ">
                                            </dx:ASPxLabel>
                                        </td>
                                        <td style="width: 370px">
                                            <dx:ASPxTextBox ID="txtLast" runat="server" Width="225px">
                                            </dx:ASPxTextBox>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td style="width: 105px">
                                            <dx:ASPxLabel ID="ASPxLabel6" runat="server" Text="ที่อยุ่ : ">
                                            </dx:ASPxLabel>
                                        </td>
                                        <td style="width: 370px">
                                            <dx:ASPxTextBox ID="txtAdd0" runat="server" Width="170px">
                                            </dx:ASPxTextBox>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td style="width: 105px">
                                            <dx:ASPxLabel ID="ASPxLabel19" runat="server" Text="จังหวัด:">
                                            </dx:ASPxLabel>
                                        </td>
                                        <td style="width: 370px">
                                            <asp:DropDownList ID="dlPro" runat="server" AutoPostBack="True" 
                                                DataSourceID="SqlProvince" DataTextField="PROVINCE_NAME" 
                                                DataValueField="PROVINCE_ID" Width="170px">
                                            </asp:DropDownList>
                                            <asp:SqlDataSource ID="SqlProvince" runat="server" 
                                                ConnectionString="<%$ ConnectionStrings:DB_Udrink %>" 
                                                SelectCommand="SELECT TOP (1000) PROVINCE_ID, PROVINCE_CODE, PROVINCE_NAME FROM TB_Province ORDER BY PROVINCE_NAME">
                                            </asp:SqlDataSource>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td style="width: 105px">
                                            <dx:ASPxLabel ID="ASPxLabel20" runat="server" Text="อำเภอ:">
                                            </dx:ASPxLabel>
                                        </td>
                                        <td style="width: 370px">
                                            <asp:DropDownList ID="dlAmp" runat="server" AutoPostBack="True" 
                                                DataSourceID="SqlAumphur" DataTextField="AMPHUR_NAME" 
                                                DataValueField="AMPHUR_ID" Width="170px">
                                            </asp:DropDownList>
                                            <asp:SqlDataSource ID="SqlAumphur" runat="server" 
                                                ConnectionString="<%$ ConnectionStrings:DB_Udrink %>" 
                                                SelectCommand="SELECT AMPHUR_ID, AMPHUR_CODE, AMPHUR_NAME, PROVINCE_ID FROM TB_Aumphur WHERE (PROVINCE_ID = @PROVINCE_ID)">
                                                <SelectParameters>
                                                    <asp:ControlParameter ControlID="dlPro" Name="PROVINCE_ID" 
                                                        PropertyName="SelectedValue" Type="Int32" />
                                                </SelectParameters>
                                            </asp:SqlDataSource>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td style="width: 105px">
                                            <dx:ASPxLabel ID="ASPxLabel21" runat="server" Text="ตำบล:">
                                            </dx:ASPxLabel>
                                        </td>
                                        <td style="width: 370px">
                                            <asp:DropDownList ID="dlDis" runat="server" AutoPostBack="True" 
                                                DataSourceID="SqlDistrict" DataTextField="DISTRICT_NAME" 
                                                DataValueField="DISTRICT_ID" Width="170px">
                                            </asp:DropDownList>
                                            <asp:SqlDataSource ID="SqlDistrict" runat="server" 
                                                ConnectionString="<%$ ConnectionStrings:DB_Udrink %>" 
                                                SelectCommand="SELECT [DISTRICT_ID], [DISTRICT_CODE], [DISTRICT_NAME], [AMPHUR_ID], [PROVINCE_ID] FROM [TB_District] WHERE (([PROVINCE_ID] = @PROVINCE_ID) AND ([AMPHUR_ID] = @AMPHUR_ID))">
                                                <SelectParameters>
                                                    <asp:ControlParameter ControlID="dlPro" Name="PROVINCE_ID" 
                                                        PropertyName="SelectedValue" Type="Int32" />
                                                    <asp:ControlParameter ControlID="dlAmp" Name="AMPHUR_ID" 
                                                        PropertyName="SelectedValue" Type="Int32" />
                                                </SelectParameters>
                                            </asp:SqlDataSource>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td style="width: 105px">
                                            <dx:ASPxLabel ID="ASPxLabel8" runat="server" Text="พนักงานทำรายการ : ">
                                            </dx:ASPxLabel>
                                        </td>
                                        <td style="width: 370px">
                                            <asp:DropDownList ID="ddlEmp" runat="server" DataSourceID="SqlEmp" 
                                                DataTextField="Fullanme" DataValueField="ID_Card">
                                            </asp:DropDownList>
                                            <asp:SqlDataSource ID="SqlEmp" runat="server" 
                                                ConnectionString="<%$ ConnectionStrings:DB_Udrink %>" 
                                                SelectCommand="SELECT ID_Card, Firstname + '    ' + Lastname AS Fullanme FROM TB_Employee">
                                            </asp:SqlDataSource>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td style="width: 105px">
                                            <dx:ASPxLabel ID="ASPxLabel7" runat="server" Text="สถานะ : ">
                                            </dx:ASPxLabel>
                                        </td>
                                        <td style="width: 370px">
                                            <asp:DropDownList ID="ddlStatus" runat="server" DataSourceID="SqlStatus" 
                                                DataTextField="StatusLoan_Name" DataValueField="StatusLoan_ID">
                                            </asp:DropDownList>
                                            <asp:SqlDataSource ID="SqlStatus" runat="server" 
                                                ConnectionString="<%$ ConnectionStrings:DB_Udrink %>" 
                                                SelectCommand="SELECT StatusLoan_ID, StatusLoan_Name FROM TB_StatusLoan">
                                            </asp:SqlDataSource>
                                        </td>
                                    </tr>
                                </table>
                            </asp:Panel>
                        </td>
                        <td style="height: 18px" align "top">
                            <asp:Panel ID="Panel3" runat="server">
                                <table style="width:100%;">
                                    <tr>
                                        <td style="width: 80px">
                                            <dx:ASPxLabel ID="ASPxLabel9" runat="server" Text="วันที่และเวลา :">
                                            </dx:ASPxLabel>
                                        </td>
                                        <td style="width: 244px">
                                            <dx:ASPxTextBox ID="txtProductId" runat="server" BackColor="#D3E4A6" 
                                                ReadOnly="True" Width="225px">
                                            </dx:ASPxTextBox>
                                        </td>
                                        <td>
                                            <dx:ASPxButton ID="btProductSert" runat="server" AutoPostBack="False" 
                                                Text="ค้นหา" Width="60px">
                                                <ClientSideEvents Click="function(s, e) {
	ShowSertProWindow();
}" />
                                            </dx:ASPxButton>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td style="width: 80px">
                                            <dx:ASPxLabel ID="ASPxLabel10" runat="server" Text="ชื่อสินค้า :">
                                            </dx:ASPxLabel>
                                        </td>
                                        <td style="width: 244px">
                                            <dx:ASPxTextBox ID="txtProductName" runat="server" BackColor="#D3E4A6" 
                                                ReadOnly="True" Width="225px">
                                            </dx:ASPxTextBox>
                                        </td>
                                        <td>
                                            <asp:HiddenField ID="chkRow" runat="server" />
                                        </td>
                                    </tr>
                                    <tr>
                                        <td style="width: 80px">
                                            <dx:ASPxLabel ID="ASPxLabel11" runat="server" Text="หน่วยนับ :">
                                            </dx:ASPxLabel>
                                        </td>
                                        <td style="width: 244px">
                                            <dx:ASPxTextBox ID="txtUnit" runat="server" BackColor="#D3E4A6" ReadOnly="True" 
                                                Width="180px">
                                            </dx:ASPxTextBox>
                                            <asp:HiddenField ID="hdUnit" runat="server" />
                                        </td>
                                        <td>
                                            &nbsp;</td>
                                    </tr>
                                    <tr>
                                        <td style="width: 80px">
                                            <dx:ASPxLabel ID="ASPxLabel12" runat="server" Text="ราคา / หน่วย :">
                                            </dx:ASPxLabel>
                                        </td>
                                        <td style="width: 244px">
                                            <dx:ASPxTextBox ID="txtUnitPrice" runat="server" Width="180px">
                                            </dx:ASPxTextBox>
                                        </td>
                                        <td>
                                            &nbsp;</td>
                                    </tr>
                                    <tr>
                                        <td style="width: 80px">
                                            <dx:ASPxLabel ID="ASPxLabel13" runat="server" Text="จำนวน :">
                                            </dx:ASPxLabel>
                                        </td>
                                        <td style="width: 244px">
                                            <dx:ASPxTextBox ID="txtCount" runat="server" ClientInstanceName="txtCount" 
                                                Style="margin-bottom: 0px" Width="180px">
                                            </dx:ASPxTextBox>
                                        </td>
                                        <td>
                                            &nbsp;</td>
                                    </tr>
                                    <tr>
                                        <td style="width: 80px">
                                            &nbsp;</td>
                                        <td style="width: 244px">
                                            <dx:ASPxLabel ID="lbWranList" runat="server" ForeColor="Red" 
                                                Text="สินค้ามีในรายการแล้ว!" Visible="False">
                                            </dx:ASPxLabel>
                                        </td>
                                        <td>
                                            <dx:ASPxButton ID="btSaveAndReport" runat="server" Height="50px" 
                                                Text="บันทึกและพิมพ์ใบเสร็จ" Width="180px" OnClick="btSaveAndReport_Click">
                                            </dx:ASPxButton>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td style="width: 80px; height: 27px">
                                            </td>
                                        <td style="width: 244px; height: 27px">
                                            <dx:ASPxButton ID="btAddList" runat="server" AutoPostBack="False" 
                                                Text="เพิ่มรายการ" OnClick="btAddList_Click">
                                            </dx:ASPxButton>
                                        </td>
                                        <td style="height: 27px">
                                            <dx:ASPxButton ID="btNewOrder" runat="server" Height="50px" 
                                                Text="เริ่มรายการใหม่" Width="180px" OnClick="btNewOrder_Click">
                                            </dx:ASPxButton>
                                        </td>
                                    </tr>
                                </table>
                            </asp:Panel>
                        </td>
                    </tr>
                    <tr>
                        <td style="height: 18px; " colspan="2">
                            <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
                                ConnectionString="<%$ ConnectionStrings:DB_Udrink %>" 
                                SelectCommand="SELECT Product_ID, Product_name FROM TB_Product">
                            </asp:SqlDataSource>
                            <asp:SqlDataSource ID="SqlDataSource2" runat="server" 
                                ConnectionString="<%$ ConnectionStrings:DB_Udrink %>" 
                                SelectCommand="SELECT Unit_ID, Unit_Name FROM TB_Unit_Category">
                            </asp:SqlDataSource>
                            <dx:ASPxGridView ID="ASPxdtail" runat="server" AutoGenerateColumns="False" 
                                KeyFieldName="Product_ID" Width="100%" OnRowCommand="ASPxdtail_RowCommand">
                                <Columns>
                                    <dx:GridViewDataTextColumn Caption="รหัสสินค้า" FieldName="Product_ID" 
                                        ShowInCustomizationForm="True" VisibleIndex="0">
                                    </dx:GridViewDataTextColumn>
                                    <dx:GridViewDataComboBoxColumn Caption="ชื่อสินค้า" FieldName="Product_ID" 
                                        ShowInCustomizationForm="True" VisibleIndex="1">
                                        <PropertiesComboBox DataSourceID="SqlDataSource1" TextField="Product_name" 
                                            ValueField="Product_ID">
                                        </PropertiesComboBox>
                                    </dx:GridViewDataComboBoxColumn>
                                    <dx:GridViewDataTextColumn Caption="จำนวน" ShowInCustomizationForm="True" 
                                        VisibleIndex="4" FieldName="Count">
                                    </dx:GridViewDataTextColumn>
                                    <dx:GridViewDataTextColumn Caption="ราคา / หน่วย" FieldName="Price" 
                                        ShowInCustomizationForm="True" VisibleIndex="2">
                                    </dx:GridViewDataTextColumn>
                                    <dx:GridViewDataComboBoxColumn Caption="หน่วยสินค้า" FieldName="Unit" 
                                        ShowInCustomizationForm="True" VisibleIndex="3">
                                        <PropertiesComboBox DataSourceID="SqlDataSource2" TextField="Unit_Name" 
                                            ValueField="Unit_ID">
                                        </PropertiesComboBox>
                                    </dx:GridViewDataComboBoxColumn>
                                    <dx:GridViewDataTextColumn Caption="รวมเป็นเงิน" FieldName="Total" 
                                        ShowInCustomizationForm="True" VisibleIndex="5">
                                    </dx:GridViewDataTextColumn>
                                    <dx:GridViewDataTextColumn Caption="ลบ" ShowInCustomizationForm="True" 
                                        VisibleIndex="6">
                                        <DataItemTemplate>
                                            <dx:ASPxButton ID="btnImageAndText" runat="server" BackColor="White" 
                                                CommandArgument='<%#Eval("Product_ID")%>' CommandName="Cmd_Delete" 
                                                Text="ลบรายการ" Width="120px">
                                                <ClientSideEvents Click="function(s,e) { e.processOnServer = confirm('Are you sure?'); }" />
                                            </dx:ASPxButton>
                                        </DataItemTemplate>
                                    </dx:GridViewDataTextColumn>
                                </Columns>
                            </dx:ASPxGridView>
                            </td>
                    </tr>
                </table>
            </dx:PanelContent>
        </PanelCollection>
    </dx:ASPxRoundPanel>
</asp:Content>
